home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWMenu / FWPullDM.h < prev   
Encoding:
Text File  |  1996-09-17  |  8.4 KB  |  260 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPullDM.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWPULLDM_H
  11. #define FWPULLDM_H
  12.  
  13. #ifndef FWMNUITM_H
  14. #include "FWMnuItm.h"
  15. #endif
  16.  
  17. #ifndef FWRESACC_H
  18. #include "FWResAcc.h"
  19. #endif
  20.  
  21. #ifndef FWTCOLL_H
  22. #include "FWTColl.h"
  23. #endif
  24.  
  25. //========================================================================================
  26. //    Forward Class Declarations
  27. //========================================================================================
  28.  
  29. class FW_CMenuBar;
  30. class FW_CPrivOrderedCollection;
  31. class ODPart;
  32. class ODMenuBar;
  33.  
  34. //========================================================================================
  35. //    class FW_CPullDownMenu
  36. //========================================================================================
  37.  
  38. class FW_CPullDownMenu
  39. {
  40. public:
  41.     FW_DECLARE_CLASS
  42.  
  43. //----------------------------------------------------------------------------------------
  44. //    Constructors/Destructors
  45. //
  46. public:
  47.     FW_CPullDownMenu(Environment* ev);
  48.     
  49.     FW_CPullDownMenu(Environment* ev, 
  50.                 const FW_CString& menuTitle);
  51.                 
  52.     FW_CPullDownMenu(Environment* ev, 
  53.                 FW_PResourceFile &resFile,
  54.                 FW_ResourceID resourceID,
  55.                 unsigned long stringID);
  56.                 
  57.     FW_CPullDownMenu(Environment* ev, 
  58.                 FW_CReadableStream& stream);
  59.     
  60.     virtual ~FW_CPullDownMenu();
  61.     
  62. //----------------------------------------------------------------------------------------
  63. //    New API
  64. //
  65. public:
  66.     //----- Getters/setters -----
  67.     ODMenuID                GetMenuID(Environment* ev) const;
  68.     const ODPlatformMenu&    GetPlatformMenu(Environment* ev) const;
  69.     
  70.     FW_Boolean                IsAttachedToMenuBar(Environment* ev) const;
  71.     FW_CMenuBar*            GetMenuBar(Environment* ev) const;
  72.     
  73.     void                    DisableAll(Environment* ev);
  74.     void                    EnableAll(Environment* ev);
  75.     
  76.     short                    CountItems(Environment* ev) const;
  77.     
  78.     ODCommandID                GetCommandID(Environment* ev, short position) const;        // position : one-based
  79.  
  80.     //----- Adding items -----
  81.     void                    AppendTextItem(Environment* ev, 
  82.                                 const FW_CString& text,
  83.                                 ODCommandID commandID,
  84.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  85.                                 
  86.     void                    InsertTextItem(Environment* ev, 
  87.                                 const FW_CString& text,
  88.                                 ODCommandID commandID,
  89.                                 short afterItem,
  90.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  91.                                 
  92.     void                    InsertTextItemAfterCommand(Environment* ev, 
  93.                                 const FW_CString& text,
  94.                                 ODCommandID commandID,
  95.                                 ODCommandID afterCommand,
  96.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  97.                                 
  98.     void                    AppendToggleItem(Environment* ev, 
  99.                                 const FW_CString& trueText,
  100.                                 const FW_CString& falseText,
  101.                                 ODCommandID commandID,
  102.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  103.                                             
  104.     void                    InsertToggleItem(Environment* ev, 
  105.                                 const FW_CString& trueText,
  106.                                 const FW_CString& falseText,
  107.                                 ODCommandID commandID,
  108.                                 short afterItem,
  109.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  110.                                             
  111.     void                    InsertToggleItemAfterCommand(Environment* ev, 
  112.                                 const FW_CString& trueText,
  113.                                 const FW_CString& falseText,
  114.                                 ODCommandID commandID,
  115.                                 ODCommandID afterCommand,
  116.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  117.                                             
  118.     void                    AppendSubMenu(Environment* ev,
  119.                                 FW_CPullDownMenu* adoptSubMenu);
  120.                                 
  121.     void                    InsertSubMenu(Environment* ev,
  122.                                 FW_CPullDownMenu* adoptSubMenu,
  123.                                 short afterItem);
  124.                                 
  125.     void                    InsertSubMenuAfterCommand(Environment* ev,
  126.                                 FW_CPullDownMenu* adoptSubMenu,
  127.                                 ODCommandID afterCommand);
  128.                                 
  129.     void                    AppendSeparator(Environment* ev);
  130.         
  131.     void                    InsertSeparator(Environment* ev,
  132.                                 short afterItem);
  133.         
  134.     void                    InsertSeparatorAfterCommand(Environment* ev,
  135.                                 ODCommandID afterCommand);
  136.         
  137.     //----- Removing items -----
  138.     void                    RemoveItem(Environment* ev, 
  139.                                 short position);
  140.                                 
  141.     //----- Archiving -----
  142.     static void*            Create(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  143.     static void                Destroy(void* object, FW_ClassTypeConstant type);
  144.     static void                InitializeFromArchive(FW_CReadableStream& stream, FW_ClassTypeConstant type, void* object);
  145.     static void             Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  146.     void                     Flatten(Environment* ev, FW_CWritableStream& stream) const;
  147.  
  148.     // ----- Parent Menu Item
  149.     FW_CMenuItem*            GetParentMenuItem(Environment* ev) const;
  150.     void                    SetParentMenuItem(Environment* ev, 
  151.                                 FW_CMenuItem* menuItem);
  152.  
  153.     // ----- Adopt Items
  154.     void                    AdoptMenuItemLast(Environment* ev, 
  155.                                 FW_CMenuItem* menuItem);
  156.     void                    AdoptMenuItemAfter(Environment* ev, 
  157.                                 FW_CMenuItem* menuItem,
  158.                                 short afterItem);
  159.                                                     
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    Internal use only
  163. //
  164. public:
  165.     void                     PrivInitialize(Environment* ev, const FW_CString& menuTitle);
  166.  
  167.     FW_CPullDownMenu*        PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const;
  168.     
  169.  
  170.     FW_CMenuItem*            PrivGetMenuItem(Environment* ev, ODCommandID commandID) const;
  171.  
  172.     void                    PrivAttachedToMenuBar(Environment* ev,
  173.                                 ODPart* part, 
  174.                                 FW_CMenuBar* menuBar, 
  175.                                 ODMenuID beforeID);
  176.     void                    PrivDetachedFromMenuBar(Environment* ev,
  177.                                 FW_CMenuBar* menuBar);
  178.  
  179.     void                    PrivAttach(Environment* ev, 
  180.                                 FW_CMenuBar* menuBar);
  181.     void                    PrivDetach(Environment* ev, 
  182.                                 FW_CMenuBar* menuBar);
  183.             
  184.     ODMenuID                PrivAcquireMenuID(Environment* ev, FW_CMenuBar* menuBar);
  185.     void                    PrivRelinquishMenuID(Environment* ev);
  186.     
  187. //----------------------------------------------------------------------------------------
  188. //    Data Members
  189. //
  190. private:
  191.     ODMenuID                                fMenuID;            // if -1 the menu is not attached
  192.     ODPlatformMenu                            fPlatformMenu;
  193.     FW_CMenuBar*                            fMenuBar;            // if NULL the menu is not attached
  194.     FW_TOrderedCollection<FW_CMenuItem>*    fItems;
  195.     FW_CMenuItem*                            fParentMenuItem;    // NULL if not a submenu
  196. };
  197.  
  198.  
  199. //========================================================================================
  200. //    Inlines
  201. //========================================================================================
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    FW_CPullDownMenu::GetMenuID
  205. //----------------------------------------------------------------------------------------
  206. inline ODMenuID FW_CPullDownMenu::GetMenuID(Environment*) const
  207. {
  208.     return fMenuID;
  209. }
  210.  
  211. //----------------------------------------------------------------------------------------
  212. //    FW_CPullDownMenu::GetPlatformMenu
  213. //----------------------------------------------------------------------------------------
  214. inline const ODPlatformMenu& FW_CPullDownMenu::GetPlatformMenu(Environment*) const
  215. {
  216.     return fPlatformMenu;
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    FW_CPullDownMenu::IsAttachedToMenuBar
  221. //----------------------------------------------------------------------------------------
  222. inline FW_Boolean FW_CPullDownMenu::IsAttachedToMenuBar(Environment*) const
  223. {
  224.     return fMenuBar != NULL;
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    FW_CPullDownMenu::GetMenuBar
  229. //----------------------------------------------------------------------------------------
  230. inline FW_CMenuBar* FW_CPullDownMenu::GetMenuBar(Environment*) const
  231. {
  232.     return fMenuBar;
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. //    FW_CPullDownMenu::GetParentMenuItem
  237. //----------------------------------------------------------------------------------------
  238. inline FW_CMenuItem* FW_CPullDownMenu::GetParentMenuItem(Environment*) const
  239. {
  240.     return fParentMenuItem;
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. //    FW_CPullDownMenu::SetParentMenuItem
  245. //----------------------------------------------------------------------------------------
  246. inline void FW_CPullDownMenu::SetParentMenuItem(Environment*, FW_CMenuItem* menuItem)
  247. {
  248.     fParentMenuItem = menuItem;
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. //    FW_CPullDownMenu::CountItems
  253. //----------------------------------------------------------------------------------------
  254. inline short FW_CPullDownMenu::CountItems(Environment*) const
  255. {
  256.     return (short) fItems->Count();
  257. }
  258.  
  259. #endif
  260.